﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualPress.Infrastructure.Entities.Repository;
using VirtualPress.Infrastructure.Entities.Enum;
using VirtualPress.Infrastructure.Entities.Cache;

namespace VirtualPress.Infrastructure.Entities.Entity
{
    public class Organization : IAccessible<T_Organization, Organization>, ILogicEntity<T_Organization, Organization>
    {
        #region Fileds
        public int Id { get; set; }

        public int OrgId { get; set; }

        public OrganizationType OrgType { get; set; }

        public string UserName { get; set; }

        public JournalStatus Status { get; set; }

        public DateTime JoinDate { get; set; }

        /// <summary>
        /// 0：邀请
        /// 1：同意
        /// 2：拒绝
        /// </summary>
        public int ApplyStatus { get; set; }

        /// <summary>
        /// 拒绝申请的原因
        /// </summary>
        public string Message { get; set; }
        #endregion

        /// <summary>
        /// 用户信息
        /// </summary>
        public User user { get; set; }
        /// <summary>
        /// 专家
        /// </summary>
        public Expert expert { get; set; }

        public Organization LoadUser()
        {
            if (!String.IsNullOrEmpty(UserName))
            {
                try
                {
                    user = new User().Find(UserName);
                }
                catch { }
            }
            return this;
        }
        public Organization LoadUser(User user, Expert expert)
        {
            this.user = user;
            this.expert = expert;
            return this;
        }

        protected override void Covariant(T_Organization model)
        {
            if (model != null)
            {
                this.Id = model.Id;
                this.JoinDate = model.JoinDate;
                this.OrgId = model.OrgId;
                this.OrgType = (OrganizationType)model.OrgType;
                this.Status = (JournalStatus)model.Status;
                this.UserName = model.UserName;
                this.ApplyStatus = model.ApplyStatus;
                this.Message = model.Message;
            }
        }

        protected override T_Organization Inverter(Organization model)
        {
            if (model != null)
            {
                return new T_Organization()
                {
                    Id = model.Id,
                    JoinDate = model.JoinDate,
                    OrgId = model.OrgId,
                    OrgType =(int)model.OrgType,
                    Status = (int)model.Status,
                    UserName = model.UserName,
                    ApplyStatus = model.ApplyStatus,
                    Message = model.Message
                };
            }
            return null;
        }

        public Organization Set(T_Organization dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
